Skip to content

Desktop: notify what this computer did, once the chain has had its say - #771

Open
dewabisma wants to merge 9 commits into
mainfrom
beast/desktop-notifications
Open

dewabisma wants to merge 9 commits into
mainfrom
beast/desktop-notifications

Conversation

@dewabisma

Copy link
Copy Markdown
Collaborator

What

The desktop now shows system notifications on macOS, Windows and Linux, for what this computer itself did, once the chain has had its say. Until now its binding of wallet_core's LocalNotifications threw UnimplementedError.

What notifies (local notifications; what happens elsewhere, such as funds received or other signers' actions, is for remote notifications, a later PR):

  • A Transparent send made here, once it is:
    • confirmed: "Sent 12.5 QTC", "From Main";
    • not seen within the 5 minutes the wallet watches for it: "Send not confirmed", "12.5 QTC from Main wasn’t seen on the chain in time. It may have failed, or only be late.";
    • marked failed: "Send failed". wallet_core never marks a send failed today (see below), so this is for when it does.
  • A proposal made here, once it is created on the chain ("Proposal created", "Send 12.5 QTC from Team"), or not seen in time ("Proposal not confirmed").

Notifications name the account or multisig and the amount, never an address. On a locked screen the system's own setting decides what shows: macOS hides the text by default.

Permission: the app starts its notifications at launch and asks macOS for permission once a wallet is open. Windows and Linux ask nothing. When notifications cannot be used (permission refused, or no notification service, as on a Linux session without one), the app keeps running and records why, for the Settings row to say.

A click brings the window to the front, restored if it was minimized or hidden, and selects the account the notification was about.

While minimized: the history polling now keeps running while the window is minimized or hidden, so that a send that never lands is still noticed. Only losing the network pauses it. What matters only on screen (prices, the swap's 1Click polling) still pauses with the window.

Not in this PR:

  • The Preferences › Notifications switch in Settings: it waits for the account-menu PRs (Move the account menu rules to wallet_core #768–Desktop: rename an account or a wallet in the sidebar #770), which change the same Settings list. The switch it will drive (notificationConfigProvider) is already respected.
  • Scheduled notifications: none on desktop yet (only the phone's reversible-transfer reminder schedules one), so scheduling fails loudly.
  • Encrypted sends: their progress lives in an autoDispose controller that only the send sheet keeps; listening to it from elsewhere would change its lifetime. A follow-up.

Code

  • providers/notifications_provider.dart: DesktopLocalNotifications, a Notifier whose state is the NotificationStatus (models/notification_status.dart: starting, not asked, allowed, turned off, unavailable with the reason). It is wallet_core's LocalNotifications (bound in app_bootstrap.dart), opens what a clicked notification was about, and notificationsStartupProvider starts it with the app and asks for permission once a wallet is open.
  • services/notification_plugin.dart: the seam over flutter_local_notifications 21.0.0, the phone's version. On macOS the plugin's initialize answers whether permission was granted, which starting does not ask for, so only Windows and Linux treat false as a failure.
  • services/own_activity_notifications.dart: watches the pending sends and proposals and notifies their outcome. A send removed from the pending sends unfound counts as given up on only once it has been watched for the poller's whole timeout, because a wallet wipe also empties that list. A created proposal leaves the pending proposals before its outcome is recorded, so the proposals are kept by hash until then.
  • ui/shell/live_data_scope.dart: polling pauses only without a network.
  • Native, bringToFront on the window channel (com.quantus.desktop-wallet/window): macOS in MainFlutterWindow.swift; Windows in the new windows/runner/window_focus.cpp; Linux in linux/runner/my_application.cc. Windows and Linux serve only this request.
  • Dependencies: flutter_local_notifications and clock in desktop-app.
  • Strings: desktopNotification*, English and Indonesian, in their own commits.

Shared code this changes

  • wallet_core: PendingTransactionPollingService.timeout is now public (it was _timeout), for the desktop's give-up rule. No behaviour changes. No mobile-app code changes.
  • desktop-app/test/fakes.dart: pumpShell takes notifications: and always fakes the system's notifications.

Found on the way (not fixed here)

wallet_core never marks a Transparent send failed, on the phone too:

  • PendingTransactionPollingService gives up after 5 minutes by removing the send from the pending sends, without marking it.
  • PendingTransactionReconciliationService's "failed" branch (more than 30 minutes old, not found) is unreachable: its "expired" check at the same 30 minutes comes first and marks the send found (inHistory) before removing it.

So the phone's "Transaction Failed" notification and the activity's failed row never show; a send that never lands just disappears. Fixing it changes phone behaviour, so it is left for its own PR.

Tests

  • desktop-app: 923 passing.
    • notifications_provider_test.dart: start-up settings per platform, permission, the status, showing, scheduling refused, showing while not allowed, the start-up with and without a wallet, an unreadable click.
    • own_activity_notifications_test.dart: each outcome above, a broadcast that fails, a wipe while a send is watched (mutation-checked: without the guard it fails), Settings off, not allowed, Indonesian, and the app watching from the start.
    • notification_click_test.dart: a click on macOS, Windows and Linux, and one about an account that is gone.
    • live_data_scope_test.dart: the minimized and hidden window now keeps polling. Two tests changed their expectations; "a catch-up that fails…" now uses the network as its trigger.
  • wallet_core: 198 passing. melos run check passed on f2ad9f71 (format, analyze, mobile 845).

Not verified yet

  • Windows and Linux native code (window_focus.cpp, my_application.cc) is compiled for the first time by this PR's CI.
  • A real run: notifications on macOS (the permission prompt, a send's notification while minimized, the click), and whether App Nap delays them while the window is minimized. Windows and Linux have not been run.

DesktopLocalNotifications now shows wallet_core's notifications through
flutter_local_notifications 21.0.0, the phone's version, on macOS, Windows
and Linux. It starts with the app and asks macOS for permission once a
wallet is open; Windows and Linux ask nothing.

Notifications that cannot be shown never stop the app: the status says why
(not asked, turned off, or unavailable with the reason), for Settings to
tell the person. A scheduled notification fails loudly, as no desktop
feature schedules one yet.
A send that never lands is only noticed by the history poll, which paused
with a window no one could see, so it could not be notified then. The
polling now pauses only without a network. What matters only on screen
(prices, the swap's 1Click polling) still pauses with the window.
The window comes to the front, restored if it was minimized or hidden, and
the account the notification named is selected while it is still there.
The window channel serves bringToFront on all three systems: macOS in
MainFlutterWindow.swift, Windows in window_focus.cpp, Linux in
my_application.cc. A click whose payload cannot be read still brings the
window forward and is reported.
A Transparent send from here notifies once it is confirmed, failed, or not
seen within the time the wallet watches for it; a proposal made here once
it is created or not seen in time. Each notification names the account or
multisig and the amount, never an address, and follows the Settings switch.

A send the wallet stops watching for is removed from the pending sends
unfound, as a wipe also removes it. Only one watched for the whole time is
taken as given up on, so that wallet_core's PendingTransactionPollingService
timeout is now public; nothing else in wallet_core changes.
@dewabisma
dewabisma requested a review from n13 November 20, 2026 17:51

@n13 n13 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: Request changes
Reviewer: GPT-6.1 Sol

Reviewed head f2ad9f71943bddb4618113b079485033c9f5094e against base 2bbd4c341f317ad6da941deb0d50321bf8891017.

  1. [P2] Handle the macOS notification click that launches the app. notification_plugin.dart:27–31

    Only the running-app callback is registered. In the pinned plugin's macOS implementation, a click received before initialization is stored in launch details and is not replayed through that callback. Consequently, quit the wallet and click a delivered notification about another account: the wallet opens on its saved account and loses the notification's target. Consume getNotificationAppLaunchDetails() at startup and retain the target until wallet/sidebar accounts have loaded before routing it. A reviewer regression using the real SystemNotificationPlugin and mocked native channel passes for a running-app click, but fails for launch: the native launch details contain the payload while the click callback receives nothing.

  2. [P2] Use the indexed amount in a confirmed Max-send notification. own_activity_notifications.dart:148–155

    The confirmation title uses PendingTransactionEvent.amount. For Max sends, RegularSendStrategy submits transfer_all, whose amount is determined at inclusion; the pending amount is an estimate and can differ when the balance or fee changes. PendingTransactionPollingService finds the actual indexed event but only changes the pending record's state/block hash, so this observer announces the estimate as the amount sent. A reviewer regression through the real poller, with pending amount 10 QTC and indexed amount 9 QTC under the same extrinsic hash, produces “Sent 10 QTC” instead of “Sent 9 QTC”. Carry the matched chain amount into the confirmation notification, covering both polling and reconciliation.

Validation: Flutter 3.47.7; locked bootstrap passed; workspace formatting and git diff --check passed; 45 focused desktop tests and 13 shared polling tests passed. The two reviewer regressions above fail at the reported assertions. Workspace analysis was stopped at the required 10-second limit. No tracked files were changed. Linux build and dependency cooldown CI passed; macOS/Windows builds and Analyze were still running at the last check. Native notification delivery was not exercised on a real desktop.

A click on a notification after the wallet was quit launches the app before
it starts its notifications, so macOS keeps the click in its launch details
instead of passing it on. The app now reads them once its notifications
have started, and keeps the clicked account until the wallet's accounts and
its saved active account have loaded, so restoring that account does not
undo the selection. A click on the running app waits the same way.

Only macOS is asked: Linux has no launch details, and the plugin registers
the app's activator with Windows only while the app runs.

Review finding 1 on #771.
A Max send is recorded with the send sheet's estimate, as the chain sizes a
transfer_all at inclusion, and finding it on the chain does not correct the
record. The Sent notification now reads the transfer the indexer holds for
the send's transaction hash, as the poller does, and says its amount. That
covers a send found by the poller and one found by reconciliation.

Without that amount there is nothing true to say, so a send the indexer
cannot be read for is reported and not notified. Failed and unconfirmed
sends keep the recorded amount: what they set out to send.

The wallet_core fix (carry the found amount onto the pending record) would
change what the phone's pending rows hold, so it waits for its own PR.

Review finding 2 on #771.
flutter_local_notifications_windows 3.0.0 builds as C++17, where the
C++/WinRT headers pull in <experimental/coroutine>, which MSVC 14.52 rejects
with STL1011. It gets the same macro local_auth_windows already builds with,
and the same guard that fails the build once the target is gone, so the app
stays on the phone's plugin version.
@dewabisma
dewabisma requested a review from n13 November 21, 2026 02:04

@n13 n13 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: Approve
Reviewer: GPT-6.1 Sol

Reviewed head ce151412c662ea677c85eccd71573d86b8daee23 against base 2bbd4c341f317ad6da941deb0d50321bf8891017, including the full PR diff and all three commits since the previous review.

No blocking findings. Both previous findings are fixed:

  • macOS launch clicks now read the plugin's launch details and retain the target until the sidebar accounts and saved active account have loaded. The running-app click path uses the same routing.
  • Confirmed-send notifications now resolve the indexed amount when a send enters inHistory, covering transitions from polling and reconciliation. A reviewer test through the real pending poller, with a 10 QTC estimate and a 9 QTC indexed transfer, emits exactly one notification saying Sent 9 QTC.

Validation on Flutter 3.47.7:

  • Locked workspace bootstrap passed.
  • 58 focused desktop tests passed, including notification/plugin/startup, click routing, background polling, bootstrap and architecture checks, plus reviewer regressions for the real poller's Max-send amount and delayed saved-account loading.
  • All 198 wallet_core tests passed.
  • Workspace formatting check and git diff --check passed. No tracked files were changed.
  • Workspace analysis was stopped at the required 10-second limit and remains incomplete locally.
  • At the final CI check, Linux build and dependency cooldown passed; macOS build, Windows build and Analyze were still running. Real desktop notification delivery, permission prompts and native window activation were not exercised interactively.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants